package dateManager;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import loginRegister.LoginBean;
import Bean.SqlBean;

/**
 *
 * @author 刘杉
 */
public class LookDateServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws  IOException {
        String userName="";
        HttpSession session=request.getSession();
        LoginBean login=(LoginBean)session.getAttribute("login");
        if(login==null){
            response.sendRedirect("http://localhost:8080/login.jsp");
        }else{
            userName=login.getUserName();
            try{
                ResultSet rs = null;
                SqlBean sb = new SqlBean();
                sb.connectSQL();
                String sql="select * from date where userName='"+userName+"'";
                rs=sb.executeQuery(sql);
                ArrayList datelist=new ArrayList();
                while(rs.next()){
                    LookDateBean dd=new LookDateBean();
                    dd.setDate(rs.getString("date"));
                    dd.setThing(rs.getString("thing"));
                    datelist.add(dd);
                }
                session.setAttribute("datelist", datelist);
                sb.closeSQL();
                response.sendRedirect("http://localhost:8080/dateManager/lookDate.jsp");
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    } 
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws  IOException {
        doGet(request, response);
    }

}